package com.edu.controller;

import com.edu.service.UserService;
import com.edu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 * @Author:mx
 * @Date:2025/9/19-14:33:41
 */
@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        UserService us = new UserServiceImpl();
        int result = us.userLogin(username, password);
        if(result == 1){
            resp.sendRedirect("success.jsp");
        }else{
            if(result == 0){
                req.setAttribute("msg","用户不存在");
            }else if(result == -1){
                req.setAttribute("msg","用户密码错误");
            }
            req.getRequestDispatcher("index.jsp").forward(req,resp);
        }

    }
}
